#include <stdio.h>
#include <stdlib.h>
#include "pac_values.h"
#include "sdl_sound_player.h"
#include "pac_logger.h"
#include "audio.h"

boolean soundIsActivated = TRUE;

boolean soundIsInitialized = FALSE;

void initSoundPlayer(void) {
    pac_log(LOG_INFO, "initSoundPlayer\n");
    if (loadPacSounds() < 0) {
        pac_log(LOG_ERROR, "Erreur lors de l'initialisation des sons!\n");
    } else {
        soundIsInitialized = TRUE;
    }
}

void activateSound(void) {
    pac_log(LOG_INFO, "activateSound\n");
    soundIsActivated = TRUE;
}

void desactivateSound(void) {
    pac_log(LOG_INFO, "desactivateSound\n");
    soundIsActivated = FALSE;
}

void swapSoundActivity(void){
    if (soundIsActivated){
        soundIsActivated = FALSE;
    }
    else{
        soundIsActivated = TRUE;
    }
}

void freePacSoundPlayer(void) {
    pac_log(LOG_INFO, "freeSoundPlayer\n");
    desactivateSound();
    freeSoundPlayer();
}

void playPacSound(Source * soundToplay) {
    // Si le moteur de son a été initialisée et que le son est activé
    if (soundIsInitialized && soundIsActivated) {
        startSound(soundToplay);
    } else {
        pac_log(LOG_DEBUG, "Son désactivé!\n");
    }
}

void playStartSound(void) {
    pac_log(LOG_DEBUG, "playStartSound\n");
    playPacSound(&START_SOUND_DATA);
}

void playPacGumEatenSound(void) {
    pac_log(LOG_DEBUG, "playPacGumEatenSound\n");
    playPacSound(&PACGUM_EATEN_SOUND_DATA);
}

void playVortexSound(void) {
    pac_log(LOG_DEBUG, "playVortexSound\n");
    playPacSound(&VORTEX_SOUND_DATA);
}

void playPowerBallEatenSound(void) {
    pac_log(LOG_DEBUG, "playPowerBallEatenSound\n");
    playPacSound(&POWERBALL_EATEN_SOUND_DATA);
}

void playExtraLifeSound(void) {
    pac_log(LOG_DEBUG, "playExtraLifeSound\n");
    playPacSound(&EXTRA_LIFE_SOUND_DATA);
}

void playEndOfPowerSound(void){
    pac_log(LOG_DEBUG, "playEndOfPowerSound\n");
    playPacSound(&ENDOFPOWER_SOUND_DATA);
}

void playWinSound(void) {
    pac_log(LOG_DEBUG, "playWinSound\n");
    playPacSound(&GAMEWIN_SOUND_DATA);
}

void playGhostEatenSound(void) {
    pac_log(LOG_DEBUG, "playGhostEatenSound\n");
    playPacSound(&GHOST_EATEN_SOUND_DATA);
}

void playPacmanEatenSound(void) {
    pac_log(LOG_DEBUG, "playPacmanEatenSound\n");
    playPacSound(&PACMAN_EATEN_SOUND_DATA);
}

void playGameOverSound(void) {
    pac_log(LOG_DEBUG, "playGameOverSound\n");
    playPacSound(&GAMEOVER_SOUND_DATA);
}

